package com.ysw.validator.custom_validator;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * @ClassName CustomLimitValidator
 * @Description 自定义注解
 * @Author ysw
 * @Date 2022/5/13 16:31
 */
public class CustomLimitValidator implements ConstraintValidator<CustomLimit,Integer> {
    private Integer num;
    @Override
    public void initialize(CustomLimit constraintAnnotation) {
        int n = constraintAnnotation.n();
        num = n;
    }

    /**
     * 是否能被n整除
     * @param integer
     * @param constraintValidatorContext
     * @return
     */
    @Override
    public boolean isValid(Integer integer, ConstraintValidatorContext constraintValidatorContext) {
        if(null != integer && integer % num == 0){
            return true;
        }
        return false;
    }
}